package centerberg.engine;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;

/**
 * An abstract class for items 
 * to be included in a Menu
 *  
 * @author Linus Centerström
 */

public abstract class MenuItem extends Component {
	private Rectangle rectangle;
	private static boolean rb;
	protected boolean isSelected;
	private Texture texture;
	
	/**
	 * Creates a new MenuItem from the Image image
	 * @param image the image used to display the MenuItem
	 */
	public MenuItem (Image image) {
		texture = new Texture(image);
		isSelected = false;
		rectangle =new Rectangle(texture.getSize().width, texture.getSize().height);
		
		Dimension dim = new Dimension((int)rectangle.getWidth() + 1 , (int)rectangle.getHeight() + 1);
		setSize(dim);
		setPreferredSize(dim);
		setMinimumSize(dim);
		setMaximumSize(dim);
		setBounds(rectangle);
	}
	
	@Override
	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D)g;
		g2.drawImage(texture.getImage(), 0, 0, (int)rectangle.getWidth(), (int)rectangle.getHeight(), texture);
		if(isSelected) {
			g2.setColor(Color.YELLOW);
			g2.draw(rectangle);
		}
	}
	public void select(boolean b) {
		isSelected = b;
	}
	/**
	 * This method is called when the
	 * MenuItem is pressed/activated
	 */
	public abstract void performAction();
	
}
